<?php
/**
 * Created by PhpStorm.
 * User: wangwenshan
 * Date: 2019/1/21
 * Time: 19:30
 */

namespace app\api\controller\v1;


use app\api\service\AppToken;
use app\api\service\UserToken;
use app\api\validate\AppTokenGet;
use app\api\validate\TokenGet;
use app\lib\exception\ParameterException;
use app\api\service\Token as TokenService;

class Token
{
    public function getToken($code=''){
        (new TokenGet())->getCheck();
        $user = new UserToken($code);
        $token = $user->get();
        return [
            'token'=>$token
        ];
    }
    public function getAppToken($ac='',$se=''){
        (new AppTokenGet())->getCheck();
        $ut = new AppToken();
//        $request = Request::instance();
//        $ac = $request->post('ac');
//        $se = $request->post('se');
        $token = $ut->get($ac,$se);
        return ['token'=>$token];
    }
    public function verifyToken($token=''){
        if(!$token){
            throw new ParameterException([
               'token不允许为空'
            ]);
        }
        $valid = TokenService::verifyToken($token);
        return [
          'isValid' => $valid
        ];
    }

}